﻿using Microsoft.Extensions.DependencyInjection;
using SYSoft.Comm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace SYSoft.ServiceExtensions
{
    /// <summary>
    /// Cors 启动服务
    /// </summary>
    public static class CorsSetup
    {
        public static void AddCorsSetup(this IServiceCollection services)
        {
            if (services == null) throw new ArgumentNullException(nameof(services));

            services.AddCors(c =>
            {
                c.AddPolicy("LimitRequests", policy =>
                {
                    // 支持多个域名端口，注意端口号后不要带/斜杆：比如localhost:8000/，是错的
                    // 注意，http://127.0.0.1:1818 和 http://localhost:1818 是不一样的，尽量写两个
                    policy
                   // .WithOrigins(Appsettings.app(new string[] { "Startup", "Cors", "IPs" }).Split(','))
                   .WithOrigins("http://127.0.0.1:8090", "http://localhost:8090", "http://localhost:1005", "http://127.0.0.1:1005", "http://localhost:1818")
                 
                    .AllowAnyHeader()//允许所有的请求头
                    .AllowAnyMethod()

                      //这里配置 .WithExposedHeaders("Content-Disposition")   
                   //是因为 Vue Axios response.headers 中默认获取不到 content - disposition 属性
                     .WithExposedHeaders("Content-Disposition"); //前端导出excel的时候使用
                });
            });
        }
    }
}
